package com.budwk.app.util;

import cn.hutool.extra.pinyin.PinyinUtil;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;

import java.io.File;
import java.util.List;

/**
 * @author XYD-PC021
 * @project wk-mini
 * @description
 * @date 2023/10/21 13:07:35
 */
public class FileUtil {

    public static String getFileName(String catalogue, String unitName) {
        String path = CommonFormOfficeUtils.getTemplatePathByOS(catalogue);
        List<File> fileList = cn.hutool.core.io.FileUtil.loopFiles(path);
        for (File file : fileList) {
            unitName = PinyinUtil.getFirstLetter(unitName, "");//获取中文首字母
            if (unitName.contains(file.getName().substring(0, file.getName().lastIndexOf("."))) &&
            !"wqmjd".equals(file.getName().substring(0, file.getName().lastIndexOf(".")))) {
                return CommonFormOfficeUtils.getTemplatePathByOS(catalogue + file.getName());
            }
            if (unitName.equals(file.getName().substring(0, file.getName().lastIndexOf(".")))) {
                return CommonFormOfficeUtils.getTemplatePathByOS(catalogue + file.getName());
            }
        }
        return null;
    }
}
